package org.koyad.portal.parser;

import java.io.InputStream;

import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;

import org.koyad.portal.tags.AbstractTag;
import org.koyad.portal.utils.LogUtils;

public class PageParser {

	private static final LogUtils LOGGER = LogUtils.getLogger(PageParser.class);

	public static AbstractTag parseTree(InputStream is, TagsHandler handler) {

		SAXParserFactory spf = SAXParserFactory.newInstance();
		spf.setNamespaceAware(true);
		
		try {
			SAXParser parser = spf.newSAXParser();
			parser.parse(is, handler);
		} catch (Exception e) {
			LOGGER.logException(e);
		}

		return handler.getTree();
	}
}
